package com.hue.nio.day02.three;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class Test02 {
    public static void main(String[] args) {
        try {
            SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("localhost", 7777));
            FileInputStream fis = new FileInputStream("E:\\1.jpg");
            FileChannel fisChannel = fis.getChannel();
            //transferTo底层用了零拷贝（在window下每次只能传输8M）
            fisChannel.transferTo(0, fisChannel.size(), socketChannel);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
